from django.db import models


# Create your models here.
# 音箱产品表
class SpeakerProduct(models.Model):
    rom_version = (
        (0, '老架构版本'),
        (1, '长连接版本')
    )

    system_version = (
        (0, 'linux'),
        (1, 'rtos'),
        (2, 'android')
    )

    speaker_name = models.CharField(max_length=50,  verbose_name='音箱名称')
    rom_version = models.SmallIntegerField(choices=rom_version, default=0, verbose_name="音箱是否为长连接版本")
    system_version = models.SmallIntegerField(choices=system_version, default=0, verbose_name="音箱底层系统版本")
    sn_key = models.CharField(max_length=255, null=True, blank=True, default='', verbose_name='SN规则关键字')
    params = models.ForeignKey('SpeakerParams', on_delete=models.CASCADE, null=True, verbose_name='配置信息')

    # 表信息声明
    class Meta:
        db_table = 'speaker_product'
        verbose_name = '音箱产品表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.speaker_name


class SpeakerParams(models.Model):
    url = models.CharField(max_length=255, default='', null=True, blank=True, verbose_name='反控接口URL')
    product_secret = models.CharField(max_length=255, default='', null=True, blank=True, verbose_name='产品密钥')
    productId = models.CharField(max_length=255, default='', null=True, blank=True, verbose_name='产品productId')
    osClientId = models.CharField(max_length=255, default='', null=True, blank=True, verbose_name='产品osClientId')
    speaker = models.ForeignKey('SpeakerProduct', on_delete=models.CASCADE, null=True, verbose_name='所属音箱')

    # 表信息声明
    class Meta:
        db_table = 'speaker_params'
        verbose_name = '产品接口信息表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.productId


# 用例模块表
class CaseModule(models.Model):
    module_name = models.CharField(max_length=50, verbose_name='模块名称')
    speaker = models.ForeignKey('SpeakerProduct', on_delete=models.CASCADE, verbose_name='音箱类型', related_name='modules')

    # 表信息声明
    class Meta:
        db_table = 'case_module'
        verbose_name = '用例模块表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.module_name


# 测试用例表
class TestCase(models.Model):
    module = models.ForeignKey('CaseModule', on_delete=models.CASCADE, verbose_name='所属模块', related_name='testcases')
    case_query = models.CharField(max_length=255, verbose_name='执行语句')
    is_smoke = models.BooleanField(default=0, verbose_name='冒烟用例')
    ex_domain = models.CharField(max_length=50, default='', verbose_name='期望domain')
    ex_intent = models.CharField(max_length=50, default='', verbose_name='期望intent')
    tts_keywords = models.CharField(max_length=255, default='', null=True, blank=True, verbose_name='TTS关键字')
    setup_query = models.CharField(max_length=255, verbose_name='前置query', null=True, blank=True)
    end_query = models.CharField(max_length=255, verbose_name='后置query', null=True, blank=True)

    # 表信息声明
    class Meta:
        db_table = 'test_case'
        verbose_name = '测试用例表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.case_query


class SpeakerAction(models.Model):
    action_type = (
        (0, 'TTS动作'),
        (1, 'TTS结束动作'),
        (2, '资源开始播放动作'),
        (3, '资源开始播放动作'),
    )

    test_case = models.ForeignKey('TestCase', on_delete=models.CASCADE, verbose_name='所属用例')
    action_type = models.SmallIntegerField(choices=action_type, default=0, verbose_name="音箱动作类型")
    keywords = models.CharField(max_length=255, null=False, verbose_name='音箱动作关键字')
